package main

import (
	"bytes"
	"context"
	"fmt"
	"os"
	"path/filepath"
	"os/exec"
	"time"
	"io/ioutil"
	"runtime"
	"strings"
	
	"gopkg.in/yaml.v3"
	wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)

// App struct
type App struct {
	ctx context.Context
}

// MkDocsConfig represents the mkdocs.yml structure
type MkDocsConfig struct {
	SiteName string                 `yaml:"site_name"`
	Theme    map[string]interface{} `yaml:"theme,omitempty"`
	Extra    map[string]interface{} `yaml:"theme,omitempty"`
}

// NewApp creates a new App application struct
func NewApp() *App {
	return &App{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
	a.ctx = ctx
}

// SelectDirectory opens a directory selection dialog
func (a *App) SelectDirectory() (string, error) {
	selection, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
		Title: "选择MkDocs项目目录",
	})
	if err != nil {
		return "", fmt.Errorf("选择目录失败: %v", err)
	}
	if selection == "" {
		return "", fmt.Errorf("未选择目录")
	}
	return selection, nil
}

// EnvironmentCheck holds environment check results
type EnvironmentCheck struct {
	PythonAvailable bool
	PipAvailable bool
	MkDocsAvailable bool
	PythonPath string
	PipCommand string
	ErrorDetails string
}

// CheckEnvironment checks Python, pip, and MkDocs availability
func (a *App) CheckEnvironment() (EnvironmentCheck, error) {
	check := EnvironmentCheck{}
	
	// Check Python availability
	if pythonPath, err := a.findPython(); err == nil {
		check.PythonAvailable = true
		check.PythonPath = pythonPath
		
		// Check pip availability
		if pipCmd, err := a.findPip(pythonPath); err == nil {
			check.PipAvailable = true
			check.PipCommand = pipCmd
		} else {
			check.ErrorDetails = fmt.Sprintf("找到Python但未找到pip: %v", err)
		}
	} else {
		check.ErrorDetails = fmt.Sprintf("未找到Python: %v", err)
	}
	
	// Check MkDocs availability
	check.MkDocsAvailable = a.isMkDocsInstalled()
	
	return check, nil
}

// GetEnvironmentDetails returns detailed environment information with guidance
func (a *App) GetEnvironmentDetails() (map[string]interface{}, error) {
	check, err := a.CheckEnvironment()
	if err != nil {
		return nil, err
	}
	
	result := map[string]interface{}{
		"pythonAvailable": check.PythonAvailable,
		"pipAvailable":   check.PipAvailable,
		"mkdocsAvailable": check.MkDocsAvailable,
		"pythonPath":     check.PythonPath,
		"pipCommand":     check.PipCommand,
		"errorDetails":    check.ErrorDetails,
		"platform":        runtime.GOOS,
		"guidance":        a.getGuidance(check),
	}
	
	return result, nil
}

// getGuidance returns user-friendly guidance based on environment check
func (a *App) getGuidance(check EnvironmentCheck) string {
	if !check.PythonAvailable {
		return "请先安装Python 3.6或更高版本。安装完成后请重启程序。\n\n" +
			"Windows: 从 https://python.org 下载并安装Python\n" +
			"macOS: 使用 Homebrew: `brew install python3` 或从 https://python.org 下载\n" +
			"Linux: 使用系统包管理器: `sudo apt install python3` (Ubuntu/Debian) 或 `sudo yum install python3` (CentOS/RHEL)\n\n" +
			"Python安装完成后，请手动安装MkDocs: `pip install mkdocs`"
	}
	
	if !check.PipAvailable {
		return "检测到Python但未找到pip。请确保pip已正确安装。\n\n" +
			"Windows: pip通常会随Python一起安装，如果没有请重新安装Python\n" +
			"macOS: 使用以下命令安装pip: `curl https://bootstrap.pypa.io/get-pip.py | python3`\n" +
			"Linux: 使用系统包管理器安装pip: `sudo apt install python3-pip` (Ubuntu/Debian) 或 `sudo yum install python3-pip` (CentOS/RHEL)\n\n" +
			"pip安装完成后，请手动安装MkDocs: `pip install mkdocs`"
	}
	
	if !check.MkDocsAvailable {
		guidance := "环境已就绪，点击\"安装MkDocs\"按钮自动安装MkDocs。\n\n" +
			"或者也可以手动安装: " + check.PipCommand + " install mkdocs\n\n" +
			"常见问题排查 (" + runtime.GOOS + "):\n"
		
		switch runtime.GOOS {
		case "windows":
			guidance += "1. 检查系统PATH环境变量是否包含Python和Scripts目录\n" +
				"2. 确保Python安装时选择了'Add Python to PATH'选项\n" +
				"3. 尝试使用完整路径安装: python -m pip install mkdocs\n" +
				"4. 如果仍然无法检测到，可以尝试重启计算机后再试"
		case "darwin":
			guidance += "1. 如果使用Homebrew安装Python，请确保/usr/local/bin在PATH中\n" +
				"2. 检查是否安装了多个Python版本导致冲突\n" +
				"3. 尝试使用pip3 install mkdocs\n" +
				"4. 如果使用pyenv管理Python版本，请确保正确设置了环境变量"
		case "linux":
			guidance += "1. 确保已安装python3-pip包\n" +
				"2. 检查/usr/local/bin和/usr/bin是否在PATH中\n" +
				"3. 尝试使用pip3 install mkdocs\n" +
				"4. 检查是否有权限问题，必要时使用sudo安装"
		default:
			guidance += "1. 确认Python和pip已正确安装\n" +
				"2. 检查PATH环境变量设置\n" +
				"3. 尝试手动安装: pip install mkdocs"
		}
		
		return guidance
	}
	
	return "环境完全就绪，可以正常使用MkDocs功能。"
}

// findPython finds Python executable with cross-platform support
func (a *App) findPython() (string, error) {
	var pythonCommands []string
	
	switch runtime.GOOS {
	case "windows":
		pythonCommands = []string{"python", "python3", "py"}
	case "darwin", "linux":
		pythonCommands = []string{"python3", "python", "/usr/local/bin/python3", "/usr/bin/python3", "/usr/local/bin/python", "/usr/bin/python"}
	default:
		pythonCommands = []string{"python3", "python"}
	}
	
	// Get current PATH and enhance it
	env := os.Environ()
	path := os.Getenv("PATH")
	
	// If PATH is empty (GUI app case), try to get it from shell
	if path == "" {
		// Try to get PATH from shell
		if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
			if shellPath, err := a.getShellPath(); err == nil {
				path = shellPath
			}
		}
	}
	
	// Define extra paths to add to PATH
	extraPaths := []string{
		"/usr/local/bin",
		"/usr/bin",
		"/bin",
		"/opt/homebrew/bin",
		"/opt/local/bin",
		"/usr/local/opt/python/libexec/bin",
		// Add user's local bin directories
		filepath.Join(os.Getenv("HOME"), ".local", "bin"),
	}
	
	// Add extra paths to PATH if not already present
	for _, extraPath := range extraPaths {
		if extraPath != "" && !strings.Contains(path, extraPath) {
			path = extraPath + ":" + path
		}
	}
	
	// Try each Python command
	for _, cmd := range pythonCommands {
		// Create command with enhanced PATH
		command := exec.Command(cmd, "--version")
		command.Env = append(env, "PATH="+path)
		
		if err := command.Run(); err == nil {
			// Get full path
			if fullPath, err := exec.LookPath(cmd); err == nil {
				return fullPath, nil
			}
			return cmd, nil
		}
	}
	
	// If still not found, try with full environment
	if path != "" {
		for _, cmd := range pythonCommands {
			command := exec.Command(cmd, "--version")
			command.Env = []string{"PATH=" + path}
			
			if err := command.Run(); err == nil {
				// Get full path
				if fullPath, err := exec.LookPath(cmd); err == nil {
					return fullPath, nil
				}
				return cmd, nil
			}
		}
	}
	
	return "", fmt.Errorf("未找到Python，请安装Python 3.6或更高版本")
}

// getShellPath attempts to get the PATH environment variable from the user's shell
func (a *App) getShellPath() (string, error) {
	// Try to get the user's shell
	shell := os.Getenv("SHELL")
	if shell == "" {
		// Default to common shells
		shells := []string{"/bin/zsh", "/bin/bash", "/bin/sh"}
		for _, s := range shells {
			if _, err := os.Stat(s); err == nil {
				shell = s
				break
			}
		}
	}
	
	if shell == "" {
		return "", fmt.Errorf("无法确定用户shell")
	}
	
	// Try to get PATH from shell
	cmd := exec.Command(shell, "-c", "echo $PATH")
	output, err := cmd.Output()
	if err != nil {
		return "", err
	}
	
	path := strings.TrimSpace(string(output))
	if path == "" {
		return "", fmt.Errorf("无法从shell获取PATH")
	}
	
	return path, nil
}

// findPip finds pip command with cross-platform support
func (a *App) findPip(pythonPath string) (string, error) {
	var pipCommands []string
	var pipArgs []string
	
	switch runtime.GOOS {
	case "windows":
		pipCommands = []string{"pip", "pip3"}
		pipArgs = []string{"--version"}
	case "darwin", "linux":
		pipCommands = []string{"pip3", "pip", "python3", "python"}
		pipArgs = []string{"-m", "pip", "--version"}
	default:
		pipCommands = []string{"pip3", "pip"}
		pipArgs = []string{"--version"}
	}
	
	// Get current PATH and enhance it
	env := os.Environ()
	path := os.Getenv("PATH")
	
	// If PATH is empty (GUI app case), try to get it from shell
	if path == "" {
		// Try to get PATH from shell
		if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
			if shellPath, err := a.getShellPath(); err == nil {
				path = shellPath
			}
		}
	}
	
	// Define extra paths to add to PATH
	extraPaths := []string{
		"/usr/local/bin",
		"/usr/bin",
		"/bin",
		"/opt/homebrew/bin",
		"/opt/local/bin",
		"/usr/local/opt/python/libexec/bin",
		// Add user's local bin directories
		filepath.Join(os.Getenv("HOME"), ".local", "bin"),
	}
	
	// Add extra paths to PATH if not already present
	for _, extraPath := range extraPaths {
		if extraPath != "" && !strings.Contains(path, extraPath) {
			path = extraPath + ":" + path
		}
	}
	
	// Add Python script paths
	if pythonDir := filepath.Dir(pythonPath); pythonDir != "" {
		scriptPath := filepath.Join(pythonDir, "Scripts") // Windows
		if _, err := os.Stat(scriptPath); err == nil {
			path = scriptPath + ":" + path
		}
		
		// Add site-packages for Unix-like systems
		if runtime.GOOS != "windows" {
			sitePackages := filepath.Join(filepath.Dir(pythonDir), "lib", "python3", "site-packages")
			if _, err := os.Stat(sitePackages); err == nil {
				path = sitePackages + ":" + path
			}
		}
	}
	
	// Try each pip command
	for _, cmd := range pipCommands {
		var args []string
		if cmd == "python3" || cmd == "python" {
			args = pipArgs
		} else {
			args = []string{"--version"}
		}
		
		testCmd := exec.Command(cmd, args...)
		testCmd.Env = append(env, "PATH="+path)
		
		if err := testCmd.Run(); err == nil {
			return cmd, nil
		}
	}
	
	// If still not found, try with full environment
	if path != "" {
		for _, cmd := range pipCommands {
			var args []string
			if cmd == "python3" || cmd == "python" {
				args = pipArgs
			} else {
				args = []string{"--version"}
			}
			
			testCmd := exec.Command(cmd, args...)
			testCmd.Env = []string{"PATH=" + path}
			
			if err := testCmd.Run(); err == nil {
				return cmd, nil
			}
		}
	}
	
	return "", fmt.Errorf("未找到pip，请安装pip")
}

// InstallMkDocs installs MkDocs using the detected pip command
func (a *App) InstallMkDocs(check EnvironmentCheck) (string, error) {
	if !check.PythonAvailable {
		return "", fmt.Errorf("未找到Python，请先安装Python 3.6或更高版本，然后手动安装MkDocs: pip install mkdocs")
	}
	
	if !check.PipAvailable {
		return "", fmt.Errorf("找到Python但未找到pip，请确保pip已正确安装，然后手动安装MkDocs: pip install mkdocs")
	}
	
	// Use the detected pip command to install MkDocs
	var args []string
	if check.PipCommand == "python3" || check.PipCommand == "python" {
		args = []string{"-m", "pip", "install", "mkdocs"}
	} else {
		args = []string{"install", "mkdocs"}
	}
	
	cmd := exec.Command(check.PipCommand, args...)
	
	// Set up output capture for better error reporting
	var output bytes.Buffer
	var stderr bytes.Buffer
	cmd.Stdout = &output
	cmd.Stderr = &stderr
	
	// Enhance environment variables for proper execution
	env := os.Environ()
	path := os.Getenv("PATH")
	if path != "" {
		// Add common Python paths
		extraPaths := []string{
			"/usr/local/bin",
			"/usr/bin",
			"/opt/homebrew/bin",
			"/opt/local/bin",
		}
		
		for _, extraPath := range extraPaths {
			if !strings.Contains(path, extraPath) {
				path = extraPath + ":" + path
			}
		}
		
		// Add Python script paths
		if pythonDir := filepath.Dir(check.PythonPath); pythonDir != "" {
			scriptPath := filepath.Join(pythonDir, "Scripts") // Windows
			if _, err := os.Stat(scriptPath); err == nil {
				path = scriptPath + ":" + path
			}
			
			// Add site-packages for Unix-like systems
			if runtime.GOOS != "windows" {
				sitePackages := filepath.Join(filepath.Dir(pythonDir), "lib", "python3", "site-packages")
				if _, err := os.Stat(sitePackages); err == nil {
					path = sitePackages + ":" + path
				}
			}
		}
	}
	
	cmd.Env = append(env, "PATH="+path)
	
	err := cmd.Run()
	if err != nil {
		errorMsg := stderr.String()
		if errorMsg == "" {
			errorMsg = err.Error()
		}
		return "", fmt.Errorf("安装MkDocs失败，请手动安装: pip install mkdocs。错误信息: %s", errorMsg)
	}
	
	return "MkDocs安装成功", nil
}

// CheckMkDocsInitialized checks if the directory has a valid mkdocs.yml file and modifies configuration
func (a *App) CheckMkDocsInitialized(directory string) (bool, error) {
	mkdocsFile := filepath.Join(directory, "mkdocs.yml")
	if _, err := os.Stat(mkdocsFile); os.IsNotExist(err) {
		return false, nil
	}

	// Read and check/modify the mkdocs.yml file
	err := a.checkAndModifyMkDocsConfig(mkdocsFile, directory)
	if err != nil {
		return true, fmt.Errorf("mkdocs.yml存在但配置检查失败: %v", err)
	}

	return true, nil
}

// checkAndModifyMkDocsConfig reads and modifies mkdocs.yml configuration
func (a *App) checkAndModifyMkDocsConfig(mkdocsFile, directory string) error {
	// Read the mkdocs.yml file
	data, err := ioutil.ReadFile(mkdocsFile)
	if err != nil {
		return fmt.Errorf("读取mkdocs.yml文件失败: %v", err)
	}

	// Parse YAML
	var config map[string]interface{}
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		return fmt.Errorf("解析mkdocs.yml文件失败: %v", err)
	}

	// Get directory name for site_name
	dirName := filepath.Base(directory)
	modified := false

	// Check and modify site_name
	if siteName, exists := config["site_name"]; exists {
		if siteNameStr, ok := siteName.(string); ok && siteNameStr == "My Docs" {
			config["site_name"] = dirName
			modified = true
		}
	} else {
		config["site_name"] = dirName
		modified = true
	}

	// Check and modify theme
	if theme, exists := config["theme"]; !exists || theme == nil {
		// Add theme: readthedocs
		config["theme"] = "readthedocs"
		modified = true
	} else {
		// If theme exists but is empty string, set it
		if themeStr, ok := theme.(string); ok && themeStr == "" {
			config["theme"] = "readthedocs"
			modified = true
		}
	}

	// Save modified configuration back to file if changes were made
	if modified {
		updatedData, err := yaml.Marshal(config)
		if err != nil {
			return fmt.Errorf("序列化配置失败: %v", err)
		}

		// Write back to file
		err = ioutil.WriteFile(mkdocsFile, updatedData, 0644)
		if err != nil {
			return fmt.Errorf("写入mkdocs.yml文件失败: %v", err)
		}
	}

	return nil
}

// InitializeMkDocs initializes a new MkDocs project in the specified directory
func (a *App) InitializeMkDocs(directory string) (string, error) {
	// Change to the target directory
	oldDir, _ := os.Getwd()
	if err := os.Chdir(directory); err != nil {
		return "", fmt.Errorf("无法切换到目录: %v", err)
	}
	defer os.Chdir(oldDir)

	// Check if mkdocs is installed
	if !a.isMkDocsInstalled() {
		return "", fmt.Errorf("MkDocs未安装，请先安装MkDocs: pip install mkdocs")
	}

	// Initialize MkDocs project
	cmd := exec.Command("mkdocs", "new", ".")
	cmd.Dir = directory // Explicitly set the working directory
	output, err := cmd.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("初始化MkDocs项目失败: %v\n%s", err, string(output))
	}

	return "MkDocs项目初始化成功", nil
}

// StartMkDocsServe starts the MkDocs server and embeds it in the webview
func (a *App) StartMkDocsServe(directory string, port string) (string, error) {
	// Check if mkdocs is installed
	if !a.isMkDocsInstalled() {
		return "", fmt.Errorf("MkDocs未安装，请先安装MkDocs: pip install mkdocs")
	}

	// Start mkdocs serve in background with explicit working directory
	cmd := exec.Command("mkdocs", "serve", "--dev-addr=127.0.0.1:"+port)
	cmd.Dir = directory // Explicitly set the working directory
	
	// Start the command
	if err := cmd.Start(); err != nil {
		return "", fmt.Errorf("启动MkDocs服务失败: %v", err)
	}

	// Wait a moment for the server to start
	go func() {
		// Load MkDocs in the webview after a short delay
		time.Sleep(3 * time.Second) // Increased delay for server startup
		wailsRuntime.EventsEmit(a.ctx, "mkdocs-started", "http://127.0.0.1:"+port)
	}()

	return fmt.Sprintf("MkDocs服务已启动在 http://127.0.0.1:%s", port), nil
}

// isMkDocsInstalled checks if mkdocs is installed
func (a *App) isMkDocsInstalled() bool {
	// Try multiple ways to check if MkDocs is installed
	var commands [][]string
	
	// Different platforms may have different ways to access MkDocs
	switch runtime.GOOS {
	case "windows":
		commands = [][]string{
			{"mkdocs", "--version"},
			{"python", "-m", "mkdocs", "--version"},
			{"python3", "-m", "mkdocs", "--version"},
			{"py", "-m", "mkdocs", "--version"},
		}
	case "darwin", "linux":
		commands = [][]string{
			{"mkdocs", "--version"},
			{"python3", "-m", "mkdocs", "--version"},
			{"python", "-m", "mkdocs", "--version"},
			{"/usr/local/bin/mkdocs", "--version"},
			{"/usr/bin/mkdocs", "--version"},
			{"/opt/homebrew/bin/mkdocs", "--version"},
			{"/usr/local/bin/python3", "-m", "mkdocs", "--version"},
			{"/usr/bin/python3", "-m", "mkdocs", "--version"},
			{"/opt/homebrew/bin/python3", "-m", "mkdocs", "--version"},
		}
	default:
		commands = [][]string{
			{"mkdocs", "--version"},
			{"python3", "-m", "mkdocs", "--version"},
			{"python", "-m", "mkdocs", "--version"},
		}
	}
	
	// Try each command until one works
	for _, cmdArgs := range commands {
		cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
		// Set environment to include common paths
		env := os.Environ()
		path := os.Getenv("PATH")
		
		// If PATH is empty (GUI app case), try to get it from shell
		if path == "" {
			// Try to get PATH from shell
			if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
				if shellPath, err := a.getShellPath(); err == nil {
					path = shellPath
				}
			}
		}
		
		// Define extra paths to add to PATH
		extraPaths := []string{
			"/usr/local/bin",
			"/usr/bin",
			"/bin",
			"/opt/homebrew/bin",
			"/opt/local/bin",
			"/opt/homebrew/lib/python3/bin",
			"/opt/local/lib/python3/bin",
			"/usr/local/opt/python/libexec/bin",
			// Add user's local bin directories
			filepath.Join(os.Getenv("HOME"), ".local", "bin"),
		}
		
		// Add extra paths to PATH if not already present
		for _, extraPath := range extraPaths {
			if extraPath != "" && !strings.Contains(path, extraPath) {
				path = extraPath + ":" + path
			}
		}
		
		// Try to find Python paths using which command (more reliable in packaged apps)
		if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
			// Try to get Python paths from which command
			if pythonPaths := a.getPythonPaths(); len(pythonPaths) > 0 {
				for _, pythonPath := range pythonPaths {
					if !strings.Contains(path, pythonPath) {
						path = pythonPath + ":" + path
					}
				}
			}
		}
		
		cmd.Env = append(env, "PATH="+path)
		
		if err := cmd.Run(); err == nil {
			return true
		}
	}
	
	// Additional check: try to find mkdocs directly in common paths
	if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
		commonMkdocsPaths := []string{
			"/usr/local/bin/mkdocs",
			"/usr/bin/mkdocs",
			"/bin/mkdocs",
			"/opt/homebrew/bin/mkdocs",
			"/opt/local/bin/mkdocs",
		}
		
		// Define extra paths to add to PATH
		extraPaths := []string{
			"/usr/local/bin",
			"/usr/bin",
			"/bin",
			"/opt/homebrew/bin",
			"/opt/local/bin",
			"/opt/homebrew/lib/python3/bin",
			"/opt/local/lib/python3/bin",
			"/usr/local/opt/python/libexec/bin",
			// Add user's local bin directories
			filepath.Join(os.Getenv("HOME"), ".local", "bin"),
		}
		
		for _, mkdocsPath := range commonMkdocsPaths {
			if _, err := os.Stat(mkdocsPath); err == nil {
				// Found mkdocs executable, try to run it
				cmd := exec.Command(mkdocsPath, "--version")
				env := os.Environ()
				path := os.Getenv("PATH")
				
				// If PATH is empty (GUI app case), try to get it from shell
				if path == "" {
					// Try to get PATH from shell
					if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
						if shellPath, err := a.getShellPath(); err == nil {
							path = shellPath
						}
					}
				}
				
				for _, extraPath := range extraPaths {
					if extraPath != "" && !strings.Contains(path, extraPath) {
						path = extraPath + ":" + path
					}
				}
				cmd.Env = append(env, "PATH="+path)
				
				if err := cmd.Run(); err == nil {
					return true
				}
			}
		}
	}
	
	return false
}

// getPythonPaths attempts to find Python paths using system commands
func (a *App) getPythonPaths() []string {
	var paths []string

	// Try different methods to find Python paths
	commands := []string{"python3", "python"}

	for _, cmdName := range commands {
		// Try 'which' command to find Python executable
		cmd := exec.Command("which", cmdName)
		if output, err := cmd.Output(); err == nil {
			path := strings.TrimSpace(string(output))
			if path != "" {
				// Add the directory containing Python executable
				dir := filepath.Dir(path)
				paths = append(paths, dir)
				
				// Add site-packages directory
				sitePackages := filepath.Join(filepath.Dir(dir), "lib", "python3", "site-packages")
				if _, err := os.Stat(sitePackages); err == nil {
					paths = append(paths, sitePackages)
				}
				
				// Add user site-packages
				userSitePackages := filepath.Join(os.Getenv("HOME"), ".local", "lib", "python3", "site-packages")
				if _, err := os.Stat(userSitePackages); err == nil {
					paths = append(paths, userSitePackages)
				}
			}
		}
	}
	
	// Add common Python installation paths
	commonPaths := []string{
		"/usr/local/bin",
		"/usr/bin",
		"/bin",
		"/opt/homebrew/bin",
		"/opt/local/bin",
		"/usr/local/opt/python/libexec/bin",
	}
	
	for _, path := range commonPaths {
		paths = append(paths, path)
	}
	
	return paths
}

